package com.synjones.wschool.face.serviceImpl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import com.synjones.wschool.face.service.OneCardService;
import com.synjones.wschool.face.utils.HttpClientUtil;
import com.synjones.wschool.onecard.api.common.ResultResp;
import com.synjones.wschool.onecard.api.req.ApiGetUserInfoReq;
import com.synjones.wschool.onecard.api.resp.ApiGetUserInfoResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 24398 on 2018/7/27.
 */
@Service
@Slf4j
public class OneCardServiceImpl implements OneCardService {
    @Value("${onecard.req.url}")
    private String basicUrl;

    private static final String URL_USER_INFO = "/user/info";
    private static final String URL_USER_INFO_BATCH = "/user/info/batch";
    @Override
    public ResultResp<ApiGetUserInfoResp> getUserInfo(ApiGetUserInfoReq req) {
        return HttpClientUtil.postJson(basicUrl + URL_USER_INFO, JSON.toJSONString(req), new TypeReference<ResultResp<ApiGetUserInfoResp>>() {
        });
    }

    @Override
    public ResultResp<List<ApiGetUserInfoResp>> batchGetUserInfo(List<String> snos) {
        return HttpClientUtil.postJson(basicUrl + URL_USER_INFO_BATCH, JSON.toJSONString(snos), new TypeReference<ResultResp<List<ApiGetUserInfoResp>>>() {
        });
    }
}
